package org.ChrisRiffle.Acme.BoundingBox.controlers;

import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import org.ChrisRiffle.Acme.BoundingBox.controlers.QueryDialogController.PANEL_TYPE;
import org.ChrisRiffle.Acme.BoundingBox.ui.BoxQueryDialog;
import org.ChrisRiffle.Acme.BoundingBox.workers.AppInitializerWorker;



/**
 * Responsible for launching the application
 * 
 * Main entry point of the application, with the main() method
 * 
 * @author RIF 
 */
public class AppLauncher {
    
    public static  final boolean DEBUG_MODE = false;
    
	/**
	 * Launches the application
	 */
	private void launch() {

	    
	  final AppInitializerWorker appInitializerWorker = new AppInitializerWorker();    			
	  
		// create/display the GUI on the Event Dispatch Thread 
		SwingUtilities.invokeLater(new Runnable() {			
			
			@Override
			public void run() {	
				
			  initLookFeel();
							  
			  // 'get' the dialog(we just want it to get built and set it's 
			  // correct size, (but not set it visible just quite yet), so we 
			  // can first display the 'loading...' panel message, without 
			  // having to worry about the size changing all over the place 
			  // when the 'component panel' gets swapped back in after the 
			  // completion of the dataset initialization process 
			  BoxQueryDialog appDialog = QueryDialogController.INSTANCE.getBoxDialog();
				
			  
			  QueryDialogController.INSTANCE.displayPanelType(PANEL_TYPE.LOADING);
			
			  appDialog.setVisible(true);
			  
			  // This worker will load the dataset points from disk into our 
			  // intermal memory data structures - ready for querying
			  // When the worker is complete, it will change the ui screen 
			  // back from "loading..."  to the main panel ready for the user
			  appInitializerWorker.execute();
			  			  			  				
			}
		});
		
	}
    

	
	
	/**
	 * inits the LookFeel
	 */
	private static void initLookFeel() {

		try {
			
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
			
		} catch (Exception e) {
			
			e.printStackTrace();
		}
	}
    
    
	/**
	 * Application entry point launches the application
	 * 
	 * @param args 
	 */
	public static void main(String[] args) {

		AppLauncher appLauncher = new AppLauncher();

		appLauncher.launch();
	}
    


}
